home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / term-source.lha / EditRoutine.c < prev    next >
C/C++ Source or Header  |  1996-10-20  |  2KB  |  115 lines

  1. /*
  2. **    EditRoutine.c
  3. **
  4. **    The common string gadget editing routine
  5. **
  6. **    Copyright © 1990-1996 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "Global.h"
  14. #endif
  15.  
  16.     /* CommonEditRoutine():
  17.      *
  18.      *    The common string gadget editing routine.
  19.      */
  20.  
  21. ULONG SAVE_DS ASM
  22. CommonEditRoutine(REG(a0) struct Hook *UnusedHook,REG(a2) struct SGWork *Work,REG(a1) Msg msg)
  23. {
  24.     BOOL GotIt;
  25.  
  26.     switch(msg->MethodID)
  27.     {
  28.             /* Hit a hit. */
  29.  
  30.         case SGH_KEY:
  31.  
  32.                 /* Right-Amiga-key was pressed, release the
  33.                  * string gadget so user may select a menu
  34.                  * item.
  35.                  */
  36.  
  37.             if((Work->IEvent->ie_Qualifier & AMIGARIGHT) && (Work->EditOp == EO_INSERTCHAR || Work->EditOp == EO_REPLACECHAR))
  38.             {
  39.                 Work->Actions    = SGA_REUSE | SGA_END;
  40.                 Work->Code        = (UWORD)-1;
  41.  
  42.                 break;
  43.             }
  44.  
  45.                 /* End input? */
  46.  
  47.             if(Work->Actions & SGA_END)
  48.             {
  49.                     /* Holding down any shift key causes the string gadget
  50.                      * not be activated again.
  51.                      */
  52.  
  53.                 if(Work->IEvent->ie_Qualifier & SHIFT_KEY)
  54.                     Work->Code = 0xFF00 | '\n';
  55.                 else
  56.                     Work->Code = 0xFF00 | '\r';
  57.  
  58.                 Work->Actions = SGA_END;
  59.  
  60.                 break;
  61.             }
  62.  
  63.                 /* xOFF or xON? */
  64.  
  65.             if(Work->Code == CONTROL_('S') || Work->Code == CONTROL_('Q'))
  66.             {
  67.                 Work->Actions     = SGA_END;
  68.                 Work->Code        |= 0xFF00;
  69.  
  70.                 break;
  71.             }
  72.  
  73.                 /* We haven't got anything useful yet. */
  74.  
  75.             GotIt = FALSE;
  76.  
  77.                 /* This looks like a function key. Send the corresponding macro. */
  78.  
  79.             if(Work->IEvent->ie_Code >= F01_CODE && Work->IEvent->ie_Code <= F10_CODE)
  80.                 GotIt = TRUE;
  81.  
  82.                 /* Amiga key + Del/Backspace clears the history list. */
  83.  
  84.             if((Work->IEvent->ie_Qualifier & (AMIGARIGHT | AMIGALEFT)) && (Work->IEvent->ie_Code == DEL_CODE || Work->IEvent->ie_Code == BACKSPACE_CODE))
  85.                 GotIt = TRUE;
  86.  
  87.                 /* Browse through the history list? */
  88.  
  89.             if(Work->IEvent->ie_Code == CURSORUP || Work->IEvent->ie_Code == CURSORDOWN)
  90.                 GotIt = TRUE;
  91.  
  92.                 /* Did we get anything sensible? */
  93.  
  94.             if(GotIt)
  95.             {
  96.                     /* Merge code and qualifier. */
  97.  
  98.                 Work->Actions    = SGA_END;
  99.                 Work->Code        = ((Work->IEvent->ie_Qualifier & (ALT_KEY|SHIFT_KEY|CONTROL_KEY)) << 8) | Work->IEvent->ie_Code;
  100.             }
  101.  
  102.             /* Fall through to... */
  103.  
  104.         case SGH_CLICK:
  105.  
  106.             break;
  107.  
  108.         default:
  109.  
  110.             return(FALSE);
  111.     }
  112.  
  113.     return(TRUE);
  114. }
  115.